package uia.is202.jpademo.data;

/*
 * Populator.java
 * Created on 16. juni 2008, 13:39
 */

import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;



/**
 * JDBC demo main class.
 * @author even
 */
public class Populator {
    
    public Populator() {
        Properties props = new Properties();
        props.put("toplink.ddl-generation", "drop-and-create-tables");
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpademo", props);
        
        //create the tables
        emf.createEntityManager().close();
        emf.close();
    }


    public void populate() {        
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpademo");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        
        Department dep1 = new Department("Stab");
        dep1.addEmployee(new Employee("Kongen", 5000000));
        dep1.addEmployee(new Employee("Prinsessa", 3000000));
        em.persist(dep1);
        
        Department dep2 = new Department("Salg");
        dep2.addEmployee(new Employee("Per", 5000));
        dep2.addEmployee(new Employee("P�l", 50000));
        dep2.addEmployee(new Employee("Espen", 5));
        em.persist(dep2);

        Department dep3 = new Department("Produksjon");
        dep3.addEmployee(new Employee("Smeden", 1000));
        dep3.addEmployee(new Employee("Snekkeren", 1000));
        dep3.addEmployee(new Employee("Slakteren", 1000));
        em.persist(dep3);

        Department dep4 = new Department("Kundest�tte");
        dep4.addEmployee(new Employee("Stallknekten", 500));
        dep4.addEmployee(new Employee("Tjenestejenta", 500));
        em.persist(dep4);

        em.getTransaction().commit();
        em.close();
        emf.close();
    }
    
    
    public static void main(String[] args) {
        System.getProperties().list(System.out);
        Populator m = new Populator();
        m.populate();
    }
    
}
